package smedi.ismedi.web.bff.controller.majorhazard;

import com.smedi.ismedi.majorhazard.api.dto.request.*;
import com.smedi.ismedi.majorhazard.api.dto.response.MajorHazardDetailResponse;
import com.smedi.ismedi.majorhazard.api.dto.response.MajorHazardLibraryResponse;
import com.smedi.ismedi.majorhazard.api.dto.response.QueryMajorHazardListResponse;
import com.smedi.ismedi.majorhazard.api.feign.RemoteMajorHazardFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 危大工程
 *
 * @author xuyuanqiao
 * @date 2021/09/02
 */
@Slf4j
@Api(value = "危大工程管理接口", tags = {"危大工程管理接口"})
@RequestMapping(value = "/webbff/v1/majorHazard")
@RestController
@AllArgsConstructor
public class MajorHazardController {
    private final RemoteMajorHazardFeignApi remoteMajorHazardFeignApi;

    /**
     * 根据id查询危大工程详情
     *
     * @param majorHazardId 需要查询的危大工程id
     * @return ResponseData<MajorHazardDetailResponse>
     */
    @ApiOperation(httpMethod = "GET", value = "根据id查询危大工程详情")
    @GetMapping(value = "/detail")
    ResponseData<MajorHazardDetailResponse> getMajorHazardDetail(@RequestParam(value = "majorHazardId") Long majorHazardId){
        return remoteMajorHazardFeignApi.getMajorHazardDetail(majorHazardId);
    }

    /**
     * 新增或修改危大工程
     *
     * @param majorHazardRequest 新增或修改危大工程请求
     * @return ResponseData<MajorHazardDetailResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "新增或修改危大工程")
    @PostMapping(value = "/add")
    ResponseData<MajorHazardDetailResponse> postAddMajorHazard(@Validated @RequestBody MajorHazardRequest majorHazardRequest){
        return remoteMajorHazardFeignApi.postAddMajorHazard(majorHazardRequest);
    }

    /**
     * 根据id删除危大工程
     *
     * @param majorHazardId 需要删除的危大工程id
     * @return ResponseData<Long>
     */
    @ApiOperation(httpMethod = "DELETE", value = "根据id删除危大工程")
    @DeleteMapping(value = "/delete")
    ResponseData<Long> getDeleteMajorHazard(@RequestParam(value = "majorHazardId") Long majorHazardId){
        return remoteMajorHazardFeignApi.getDeleteMajorHazard(majorHazardId);
    }

    /**
     * 分页查询危大工程列表
     *
     * @param dangerousSourceListRequest 分页查询危大工程请求
     * @return ResponseData<PaginationData < QueryMajorHazardListResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "分页查询危大工程列表")
    @PostMapping(value = "/pageList")
    ResponseData<PaginationData<QueryMajorHazardListResponse>> postQueryMajorHazardPageList(@Validated @RequestBody QueryMajorHazardListRequest dangerousSourceListRequest){
        return remoteMajorHazardFeignApi.postQueryMajorHazardPageList(dangerousSourceListRequest);
    }

    /**
     * 分页查询危大工程库列表
     *
     * @param queryMajorHazardLibraryPageListRequest 分页查询危大工程危库请求
     * @return ResponseData<PaginationData < MajorHazardLibraryResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "分页查询危大工程库列表")
    @PostMapping(value = "/libraryPageList")
    ResponseData<PaginationData<MajorHazardLibraryResponse>> postQueryMajorHazardLibraryPageList(@Validated @RequestBody QueryMajorHazardLibraryPageListRequest queryMajorHazardLibraryPageListRequest){
        return remoteMajorHazardFeignApi.postQueryMajorHazardLibraryPageList(queryMajorHazardLibraryPageListRequest);
    }

    /**
     * 查询危大工程库列表
     *
     * @param queryMajorHazardLibraryListRequest 查询危大工程危库请求
     * @return ResponseData<List < MajorHazardLibraryResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "查询危大工程库列表")
    @PostMapping(value = "/libraryList")
    ResponseData<List<MajorHazardLibraryResponse>> postQueryMajorHazardLibraryList(@Validated @RequestBody QueryMajorHazardLibraryListRequest queryMajorHazardLibraryListRequest){
        return remoteMajorHazardFeignApi.postQueryMajorHazardLibraryList(queryMajorHazardLibraryListRequest);
    }

    /**
     * 压缩包下载
     *
     * @param filesToZipRequest 通过压缩包下载请求
     * @return ResponseEntity<byte [ ]>
     */
    @ApiOperation(httpMethod = "POST", value = "压缩包下载")
    @PostMapping(value = "/download")
    ResponseEntity<byte[]> postDownloadFilesToZip(@Validated @RequestBody FilesToZipRequest filesToZipRequest) throws IOException{
        return remoteMajorHazardFeignApi.postDownloadFilesToZip(filesToZipRequest);
    }

    /**
     * 导出危大详情
     *
     * @param majorHazardId 危大id
     * @return
     * @throws IOException
     */
    @ApiOperation(httpMethod = "POST", value = "导出危大详情")
    @PostMapping(value = "/exportDetail")
    ResponseEntity<byte[]> exportDetail(@Validated @RequestBody List<Long> majorHazardId) throws IOException{
        return remoteMajorHazardFeignApi.exportDetail(majorHazardId);
    }

    /**
     * 导出危大列表
     *
     * @param majorHazardIds 危大id集合
     * @return
     * @throws IOException
     */
    @ApiOperation(httpMethod = "POST", value = "导出危大列表")
    @PostMapping(value = "/exportList")
    ResponseEntity<byte[]> exportList(@Validated @RequestBody List<Long> majorHazardIds) throws IOException{
        return remoteMajorHazardFeignApi.exportList(majorHazardIds);
    }
}
